package grammartest;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        List<String> heap = new ArrayList<>();
        heap.add("");// fake
        for (int i = 0; i < num; i++) {
            String curr = sc.next();
            int index = 0;
            while (index + 8 <= curr.length()) {
                heap.add(curr.substring(index, index + 8));
                index += 8;
            }
            if (index < curr.length()) {
                String last = curr.substring(index);
                for (int j = 0; j < 8 - (curr.length() - index); j++) {
                    last = last + "0";
                }
                heap.add(last);
            }
        }
        int n = heap.size() - 1;
        for (int j = n / 2; j >= 1; j--) {
            int k = j;
            String v = heap.get(k);
            boolean isHeap = false;
            while (!isHeap && 2 * k <= n) {
                int c = 2 * k;
                if (c < n) {// 如果有两个子女
                    if (compare(heap.get(c), heap.get(c + 1))) {
                        c++;
                    }
                }
                if (!compare(v, heap.get(c))) {
                    isHeap = true;
                } else {
                    heap.set(k, heap.get(c));
                    k = c;
                    heap.set(k, v);
                }
            }
        }



    }

    public static boolean compare(String a, String b) {
        for (int i = 0; i < 8; i++) {
            if (a.charAt(i) > b.charAt(i)) {
                // a > b
                return true;
            } else if (a.charAt(i) < b.charAt(i)) {
                // a <= b
                return false;
            }
        }
        return true;
    }
}
